const redis = require('redis');

const host = process.env.REDIS_HOST || '127.0.0.1';
const port = process.env.REDIS_PORT || '6379';
const password = process.env.REDIS_PASSWORD || '';

const url = password
  ? `redis://:${password}@${host}:${port}`
  : `redis://${host}:${port}`;

const client = redis.createClient({ url });

client.on('error', (err) => {
  console.error('Redis 错误:', err);
});

module.exports = client;
